#include <stdio.h>

#include<pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
void* thread_main(void * arg);

int main(int argc,char * argv[])
{
    pthread_t t_id;
    void* thr_ret;

    int thread_param =5;
    if(pthread_create(&t_id,NULL,thread_main,(void*) &thread_param) !=0)
    {
        puts("thread create error");
        return -1;
    }
    if(pthread_join(t_id,&thr_ret)!=0)
    {
        puts("error\n");
        return 0;
    }
    printf("Thread from return message :%s\n",(char*) thr_ret);
    free(thr_ret);

    return 0;
}

void* thread_main(void * arg)
{

    int cnt = *(int *) arg;
    char * msg = (char*) malloc(50*sizeof(char));
    strcpy(msg,"hello, I am thread \n");

    for(int i=0;i<cnt;i++)
    {
        sleep(1);
        puts("running thread");
    }
    return (void*) msg;
} 